package com.hero.tweaks.ui.activities;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.provider.Settings;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.hero.tweaks.R;
import com.hero.tweaks.util.AxisPreferenceActivity;
import com.hero.tweaks.util.CMDProcessor;
import com.hero.tweaks.util.Helpers;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceScreen;

public class HideIcons extends AxisPreferenceActivity implements
		Preference.OnPreferenceChangeListener,
		OnSharedPreferenceChangeListener {

	private static final String PREF_STATUSBAR_HIDE_ALARM = "pref_statusbar_hide_alarm";
	private static final String PREF_STATUSBAR_HIDE_BATTERY = "pref_statusbar_hide_battery";
	private static final String PREF_STATUSBAR_HIDE_BLUETOOTH = "pref_statusbar_hide_bluetooth";
	//private static final String PREF_STATUSBAR_HIDE_DATA = "pref_statusbar_hide_data";
	private static final String PREF_STATUSBAR_HIDE_GPS = "pref_statusbar_hide_gps";
	private static final String PREF_STATUSBAR_HIDE_HEADPHONES = "pref_statusbar_hide_headphones";
	//private static final String PREF_STATUSBAR_HIDE_MUSIC = "pref_statusbar_hide_music";
	//private static final String PREF_STATUSBAR_HIDE_NFC = "pref_statusbar_hide_nfc";
	//private static final String PREF_STATUSBAR_HIDE_SIGNAL = "pref_statusbar_hide_signal";
	private static final String PREF_STATUSBAR_HIDE_SYNC = "pref_statusbar_hide_sync";
	private static final String PREF_STATUSBAR_HIDE_VOLUME = "pref_statusbar_hide_volume";
	//private static final String PREF_STATUSBAR_HIDE_WIFI = "pref_statusbar_hide_wifi";
	//private static final String PREF_HIDE_HTCSYNC = "pref_hide_htcsync";
	//private static final String PREF_HIDE_IME = "pref_hide_ime";
	private static final String PREF_HIDE_MTP = "pref_hide_mtp";
	private static final String PREF_HIDE_POWERSAVER = "pref_hide_powersaver";
	private static final String PREF_HIDE_USB = "pref_hide_usb";
	
	

	CheckBoxPreference mStatusBarHideAlarm;
	CheckBoxPreference mStatusBarHideBattery;
	CheckBoxPreference mStatusBarHideBluetooth;
	//CheckBoxPreference mStatusBarHideData;
	CheckBoxPreference mStatusBarHideGps;
	CheckBoxPreference mStatusBarHideHeadphones;
	//CheckBoxPreference mStatusBarHideMusic;
	//CheckBoxPreference mStatusBarHideNfc;
	//CheckBoxPreference mStatusBarHideSignal;
	CheckBoxPreference mStatusBarHideSync;
	CheckBoxPreference mStatusBarHideVolume;
	//CheckBoxPreference mStatusBarHideWifi;
	//CheckBoxPreference mHideHtcSync;
	//CheckBoxPreference mHideIme;
	CheckBoxPreference mHideMtp;
	CheckBoxPreference mhidePowerSaver;
	CheckBoxPreference mHideUsb;
	

	public void Hreboot() {
		CMDProcessor.runSuCommand("setprop ctl.restart zygote");
	}

	@SuppressWarnings("deprecation")
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		overridePendingTransition(R.anim.translate_to_right_in, R.anim.hold_out);

		addPreferencesFromResource(R.xml.prefs_hide_icons);

		mStatusBarHideAlarm = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_ALARM);
		mStatusBarHideAlarm.setOnPreferenceChangeListener(this);
		mStatusBarHideAlarm.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_alarm", 0) == 1));
		
		mStatusBarHideBattery = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_BATTERY);
		mStatusBarHideBattery.setOnPreferenceChangeListener(this);
		mStatusBarHideBattery.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_battery_icon", 0) == 1));

		mStatusBarHideBluetooth = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_BLUETOOTH);
		mStatusBarHideBluetooth.setOnPreferenceChangeListener(this);
		mStatusBarHideBluetooth.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_bluetooth", 0) == 1));

		/*mStatusBarHideData = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_DATA);
		mStatusBarHideData.setOnPreferenceChangeListener(this);
		mStatusBarHideBluetooth.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_data_icon", 0) == 1));*/

		mStatusBarHideGps = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_GPS);
		mStatusBarHideGps.setOnPreferenceChangeListener(this);
		mStatusBarHideGps.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_gps", 0) == 1));
		
		mStatusBarHideHeadphones = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_HEADPHONES);
		mStatusBarHideHeadphones.setOnPreferenceChangeListener(this);
		mStatusBarHideHeadphones.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_headphones", 0) == 1));
		
		/*mStatusBarHideMusic = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_MUSIC);
		mStatusBarHideMusic.setOnPreferenceChangeListener(this);
		mStatusBarHideMusic.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_music_icon", 0) == 1));*/
		
		/*mStatusBarHideNfc = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_NFC);
		mStatusBarHideNfc.setOnPreferenceChangeListener(this);
		mStatusBarHideNfc.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_nfc", 0) == 1));*/
		
		/*mStatusBarHideSignal = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_SIGNAL);
		mStatusBarHideSignal.setOnPreferenceChangeListener(this);
		mStatusBarHideSignal.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_signal_bars", 0) == 1));*/
				
		mStatusBarHideSync = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_SYNC);
		mStatusBarHideSync.setOnPreferenceChangeListener(this);
		mStatusBarHideSync.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_sync_icon", 0) == 1));

		mStatusBarHideVolume = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_VOLUME);
		mStatusBarHideVolume.setOnPreferenceChangeListener(this);
		mStatusBarHideVolume.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_volume", 0) == 1));

		/*mStatusBarHideWifi = (CheckBoxPreference) findPreference(PREF_STATUSBAR_HIDE_WIFI);
		mStatusBarHideWifi.setOnPreferenceChangeListener(this);
		mStatusBarHideWifi.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_wifi_icon", 0) == 1));*/
		
		/*mHideHtcSync = (CheckBoxPreference) findPreference(PREF_HIDE_HTCSYNC);
		mHideHtcSync.setOnPreferenceChangeListener(this);
		mHideHtcSync.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_htcsync_notification", 0) == 1));*/
		
		/*mHideIme = (CheckBoxPreference) findPreference(PREF_HIDE_IME);
		mHideIme.setOnPreferenceChangeListener(this);
		mHideIme.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_ime", 0) == 1));*/
		
		mHideMtp = (CheckBoxPreference) findPreference(PREF_HIDE_MTP);
		mHideMtp.setOnPreferenceChangeListener(this);
		mHideMtp.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_mtp_notification", 0) == 1));
		
		mhidePowerSaver = (CheckBoxPreference) findPreference(PREF_HIDE_POWERSAVER);
		mhidePowerSaver.setOnPreferenceChangeListener(this);
		mhidePowerSaver.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_powersaver_notification", 0) == 1));
		
		mHideUsb = (CheckBoxPreference) findPreference(PREF_HIDE_USB);
		mHideUsb.setOnPreferenceChangeListener(this);
		mHideUsb.setChecked((Settings.System.getInt(
				getContentResolver(), "tweaks_hide_usb_notification", 0) == 1));

	}

	@Override
	public boolean onPreferenceChange(Preference preference, Object objValue) {

		if (preference == mStatusBarHideAlarm) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_alarm",
					value);
			return true;
			
		} else if (preference == mStatusBarHideBattery) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_battery_icon",
					value);
			return true;
		
		} else if (preference == mStatusBarHideBluetooth) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(),"tweaks_hide_bluetooth", 
					value);
			return true;
			
		/*} else if (preference == mStatusBarHideData) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(),"tweaks_hide_data_icon", 
					value);
			return true;*/
			
		} else if (preference == mStatusBarHideGps) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_gps",
					value);
			return true;
			
		} else if (preference == mStatusBarHideHeadphones) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_headphones",
					value);
			return true;
			
		/*} else if (preference == mStatusBarHideMusic) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_music_icon",
					value);
			return true;*/
			
		/*} else if (preference == mStatusBarHideNfc) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_nfc",
					value);
			return true;*/
			
		/*} else if (preference == mStatusBarHideSignal) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_signal_bars",
					value);
			return true;*/
			
		} else if (preference == mStatusBarHideSync) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_sync_icon",
					value);
			return true;
			
		} else if (preference == mStatusBarHideVolume) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_volume",
					value);
			return true;
			
		/*} else if (preference == mStatusBarHideWifi) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_wifi_icon",
					value);
			return true;*/
			
		/*} else if (preference == mHideHtcSync) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_htcsync_notification",
					value);
			return true;*/
			
		/*} else if (preference == mHideIme) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_ime",
					value);
			return true;*/
			
		} else if (preference == mHideMtp) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_mtp_notification",
					value);
			return true;
			
		} else if (preference == mhidePowerSaver) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_powersaver_notification",
					value);
			return true;
			
		} else if (preference == mHideUsb) {
			boolean checked = ((CheckBoxPreference) preference).isChecked();
			int value = (checked ? 0 : 1);
			Settings.System.putInt(getContentResolver(), "tweaks_hide_usb_notification",
					value);
			return true;
			
	    }
		return false;
	}

	@Override
	public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
			Preference preference) {

		return super.onPreferenceTreeClick(preferenceScreen, preference);
	}

	@Override
	public void onSharedPreferenceChanged(SharedPreferences arg0, String arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenu.ContextMenuInfo menuInfo) {
		super.onCreateContextMenu(menu, v, menuInfo);
		menu.add("ContextMenu");
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		menu.add(1, 1, 1, R.string.restart_shell);

		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		item.getMenuInfo();
		switch (item.getItemId()) {
		case 1:
			Helpers.restartHotreboot();
		default:
			return super.onContextItemSelected(item);
		}
	}
}
